﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SIPO.Library.DomainObject.Administration.Catalog;
using SIPO.Library.DomainObject.Administration.UserManagement;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DataAccess.Administration.Catalog;
using SIPO.Library.DataAccess.Administration.UserManagement;
using System.Configuration;
using SIPO.Web.Support;
using System.Globalization;

namespace SIPO.Web.Forms.Transaction
{
    public partial class ObjectionResponseform : BasePage
    {
        private int id = -1;
        private int add = 0;
        protected override void OnLoad(EventArgs e)
        {
            recObjectionRepo objectionDal = new recObjectionRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
            

            if (Request.Params["id"] != null)
            {
                id = Convert.ToInt32(Request.Params["id"]);
            }
            if (Request.Params["isedit"] != null)
            {
                add = Convert.ToInt32(Request.Params["isedit"]);
            }

            recObjection objection = objectionDal.GetById(id);

            if (add == 0)
            {
                hfObjectionId.Value = objection.ObjectionID.ToString();
                hfID.Value = id.ToString();
                txtNoSuratKeberatan.Text = objection.ObjectionNo;
                hfObjectionNo.Value = objection.ObjectionNo;
            }
            else 
            {
                hfObjectionId.Value = objection.ObjectionID.ToString();
                hfID.Value = id.ToString();
                txtNoSurat.Text = objection.ResponNo;
                txtCatatan.Text = objection.ResponNote;
                DateTime tgl = Convert.ToDateTime(objection.ResponDate);
                txtTglSurat.Text = tgl.ToString("dd-MM-yyyy");
                txtNoSuratKeberatan.Text = objection.ObjectionNo.ToString();
            }
            hfNoSurat.Value = objection.ResponNo == null ? string.Empty : objection.ResponNo.ToString();
            GetPrivilege();
        }
        private void GetPrivilege()
        {
            Membership membership = new Membership(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);

            List<recAccessRights.AccessRights> accessRights = membership.GetAccessRights(base.UserID, base.MenuID);

            accessRights.ForEach(delegate(recAccessRights.AccessRights access)
            {
                switch (access)
                {

                    case (recAccessRights.AccessRights.Add):
                        ClientScript.RegisterStartupScript(typeof(Page), "add", "$('#btnSave').show();", true);
                        break;
                    case (recAccessRights.AccessRights.Edit):
                        ClientScript.RegisterStartupScript(typeof(Page), "edit", "$('#btnSave').show();", true);
                        break;
                }
            });

        }
    }
}
